package org.example.http;


import com.alibaba.druid.pool.DruidPooledConnection;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SiteUserService {
    public static List<Map<String, Object>> siteUserList = new ArrayList<>();

    /**
     * 初始化数据
     */
    public static void initData() {
        DruidPooledConnection connection = null;
        try {
            connection = DataHandler.mysqlsource.getConnection();

            String sql = "select * from site_user";
            PreparedStatement statement = connection.prepareStatement(sql);
            ResultSet resultSet = statement.executeQuery();
            while (resultSet.next()) {
                Map<String, Object> map = new HashMap<>();
                map.put("user_id", resultSet.getString("user_id"));
                map.put("user_name", resultSet.getString("user_name"));
                map.put("idcard", resultSet.getString("idcard"));
                map.put("telphone", resultSet.getString("telphone"));
                map.put("xqcode", resultSet.getString("xqcode"));
                siteUserList.add(map);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (connection != null) {
                try {
                    connection.close();
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        }
    }
}
